package fr.mairie.parc.page.commande;

import java.util.List;

import javax.annotation.Resource;

import org.apache.click.control.PageLink;
import org.apache.click.dataprovider.DataProvider;
import org.apache.click.util.Bindable;
import org.springframework.context.ApplicationContext;

import fr.mairie.parc.context.AppContext;
import fr.mairie.parc.control.commande.CommandeTable;
import fr.mairie.parc.domain.Commande;
import fr.mairie.parc.page.BorderPage;
import fr.mairie.parc.service.CommandeManager;

public class ListCommandePage extends BorderPage {


	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	@Resource protected CommandeManager commandeManager;
	@Bindable protected CommandeTable resultTable = new CommandeTable("resultTable", this, ViewCommandePage.class);

	public ListCommandePage() {

		resultTable.setDataProvider(new DataProvider<Commande>() {
			private static final long serialVersionUID = 1L;
			public Iterable<Commande> getData() {
				List<Commande> res = commandeManager.selectAll();
		    	return res;
		    }
		});

		PageLink validationRowLink = new PageLink("Validate", EditCommandePage.class);
		validationRowLink.setImageSrc("/assets/images/16x16/application_form_edit.png");
		validationRowLink.setTitle("Edit Validation");
		//validationRowLink.setParameter("referrer", "list-user-dif-request.htm");

		resultTable.addActionColumnLink(validationRowLink);
	}

	@Override
	public void onInit() {
		super.onInit();
		ApplicationContext ctx = AppContext.getApplicationContext();
    	commandeManager = (CommandeManager) ctx.getBean("commandeManager");
	}

}
